/**
 * created by 文阿花, 2021/4/22
 * Copyright (c) 2021, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
package com.light.mytext.javaknowledge.datastructure;

import android.util.Log;

/**
 * 描 述：动态栈（通过链表实现栈）
 * 作 者：文阿花  2021-04-22 10:45
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
public  class LinkTableStackText<T> {

    public class Node {
        private T t;
        private Node next;

        public Node(T t, Node next) {
            this.t = t;
            this.next = next;
        }

        public Node(T t) {
            this.t = t;
        }

    }

    public Node head;//头结点
    public int size;

    //构造函数
    public LinkTableStackText() {
        this.head = null;
        this.size = 0;
    }

    //入栈
    public void pushStack(T t) {
        if (t == null) {
            throw new NullPointerException("参数不能为空");
        }
        if (head == null) {
            head = new Node(t);
            head.next = null;
            size++;
        } else {
            Node cur = this.head;
            head = new Node(t);
            head.t = t;
            head.next = cur;
            size++;
        }
    }

    //出栈
    public void outStack() {
        head = head.next;
        size--;
    }

    //获取栈顶元素
    public T getTopData() {
        return head.t;
    }

    //判断是否为空
    public boolean isEmpty() {
        if (head == null) {
            return true;
        } else {
            return false;
        }
    }

    public String ToSting() {
        StringBuffer sb = new StringBuffer("");
        Node current = this.head;
        while (current != null) {
            sb.append(current.t + ",");
            current = current.next;
        }
        sb.append("NULL");
        return sb.toString();
    }

    /**
     * 打印
     */
    public void logMess() {
        Log.i("LinkTableActivity==", this.ToSting());
    }


}
